# -*- coding: utf-8 -*-
# @Author  : wyh
# @Time    : 2023/2/12 15:31
# @File    : orm查询
# @Email   : 2448979539@qq.com
import os
import django
import pandas

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'application.settings')
django.setup()

from django.contrib.gis.geos import Point
from django.contrib.gis.geos.polygon import Polygon
from world.models import WorldBorder


point = Point(-114.1, 38.1)
queryset = WorldBorder.objects.filter(mpoly__contains=point)
print('sql:', queryset.query)
print('len: ', queryset.count())
print('queryset: ', queryset)
china_mat = queryset.first().mpoly


china_df = pandas.DataFrame(china_mat)
print('china_dataframe.shape', china_df.shape)

for p in china_mat:
    p: Polygon
    Polygon()
    print(len(p), type(p), p.num_points)